package Controller.ArticleController;

import Model.Article;
import Service.ArticleService;
import Utils.ServiceFactory;
import com.alibaba.fastjson.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/Article/all.do")
public class ShowAll extends HttpServlet {
    ArticleService articleService = ServiceFactory.getArticleService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");
        List<Article> articles = articleService.fAllArticles();
        JSONArray jsonArray = (JSONArray) JSONArray.toJSON(articles);
        resp.getWriter().println(jsonArray.toString());
    }
}
